import sys
sys.path.append('../kernel')
from model import Model
class TaskModel(Model):
    def __init__(self):
        #链接数据库
        super().__init__()
    #获取气象数据执行的
    def get_city_weather(self):
        # 执行查询
        sql = "select sign,update_time from task WHERE id='city_weather'"
        # sql = "select id,`name` from city"
        self.cursor.execute(sql)
        data=self.cursor.fetchone()
        return data
    def save_city_weather(self,sign,update_time):
        # 执行查询
        sql = "UPDATE task SET sign='%s',update_time='%d' WHERE id='city_weather'" % (sign,update_time)
        # sql = "select id,`name` from city"
        self.cursor.execute(sql)

    def save_city_xcurl_1(self,sign,update_time):
        # 执行查询
        sql = "UPDATE task SET sign='%s',update_time='%d' WHERE id='city_hotel_xcurl_1'" % (sign,update_time)
        # sql = "select id,`name` from city"
        self.cursor.execute(sql)

    def save_sign_by_id(self,sign,update_time,id):
        # 执行查询
        sql = "UPDATE task SET sign='%s',update_time='%d' WHERE id='%s'" % (sign,update_time,id)
        # sql = "select id,`name` from city"
        self.cursor.execute(sql)

    #获取携程酒店第一层url执行记录
    def get_xcurl_1(self):
        # 执行查询
        sql = "select sign,update_time from task WHERE id='city_hotel_xcurl_1'"
        self.cursor.execute(sql)
        data = self.cursor.fetchone()
        return data
    def get_sign_by_id(self,id):
        # 执行查询
        sql = "select sign,update_time from task WHERE id='%s'" % id
        self.cursor.execute(sql)
        data = self.cursor.fetchone()
        return data
    def __del__(self):
        #计数数据库链接
        self.cursor.close()
        self.conn.close()